﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wedn.DAL;
using Wedn.Model.Data;

namespace Wedn.BLL.Data
{
    /// <summary>
    /// 标签管理抽象类不可被实例化(初步审核通过)
    /// </summary>
    public class TermsManager
    {
        #region 增加标签
        /// <summary>
        /// 向标签表中插入一行数据, 返回执行是否成功
        /// </summary>
        /// <param name="term">要插入的对象</param>
        /// <returns>执行是否成功</returns>
        public static bool Insert(Term term)
        {
            return TermsDAO.Insert(term) > 0;
        }
        #endregion

        #region 删除标签

        #region 删除一条
        /// <summary>
        /// 根据id删除对应的标签记录, 返回执行是否成功
        /// </summary>
        /// <param name="termid">要删除记录的ID</param>
        /// <returns>执行是否成功</returns>
        public static bool Delete(int termid)
        {
            return TermsDAO.Delete(termid) > 0;
        }
        #endregion

        #region 删除多条
        /// <summary>
        /// 根据id数组删除对应的标签记录, 返回执行是否成功
        /// </summary>
        /// <param name="termids">要删除记录的ID数组</param>
        /// <returns>执行是否成功</returns>
        public static bool Delete(int[] termids)
        {
            string ids = string.Join(",", termids);
            return TermsDAO.Delete(ids) == termids.Length;
        }
        #endregion

        #endregion

        #region 更新标签
        /// <summary>
        /// 根据标签对象ID属性更新一个标签对象, 返回执行是否成功
        /// </summary>
        /// <param name="term">要更新的对象</param>
        /// <returns>执行是否成功</returns>
        public static bool Update(Term term)
        {
            return TermsDAO.Update(term) > 0;
        }
        #endregion

        #region 选取标签

        #region 获取表中主键最大值
        /// <summary>
        /// 获取表中主键最大值
        /// </summary>
        /// <returns>主键最大值</returns>
        public static int GetMaxId()
        {
            return TermsDAO.GetMaxId();
        }
        #endregion

        #region 选取全部标签集合
        /// <summary>
        /// 取出当前标签表中的所有拓展元数据信息集合
        /// </summary>
        /// <returns>标签信息集合</returns>
        public static List<Term> GetTerms()
        {
            return TermsDAO.SelectTerms();
        }
        #endregion

        #region 根据类型选取标签对象
        /// <summary>
        /// 根据类型选取标签对象
        /// </summary>
        /// <param name="termType">标签类型</param>
        /// <returns>标签对象</returns>
        public static List<Term> GetTerms(string termType)
        {
            return TermsDAO.SelectTerms(termType);
        }
        #endregion

        #region 根据ID选取标签对象
        /// <summary>
        /// 根据ID选取标签对象
        /// </summary>
        /// <param name="termid">标签ID</param>
        /// <returns>标签对象</returns>
        public static Term GetTerm(int termid)
        {
            return TermsDAO.SelectTerm(termid);
        }
        #endregion

        #region 根据ID和类型选取标签对象
        /// <summary>
        /// 根据ID和类型选取标签对象
        /// </summary>
        /// <param name="termid">标签ID</param>
        /// <returns>标签对象</returns>
        public static Term GetTerm(int termid, string termType)
        {
            return TermsDAO.SelectTerm(termid, termType);
        }
        #endregion

        #region 根据类型选取标签总数
        /// <summary>
        /// 根据类型选取标签总数
        /// </summary>
        /// <returns>总数</returns>
        public static int GetTermsCount(string termType)
        {
            return TermsDAO.SelectTermsCount(termType);
        }
        #endregion

        #endregion
    }
}
